#!/usr/bin/env python
# Copyright (C) 2008 Marcin Cieslik <marcin.cieslik@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

from numpy.random import random
from math import log, ceil
from numpy import copy
from ckd3_lib import kdtree
from timeit import Timer

def kdt(i, b):
    A = random(i).reshape((i/3,3))
    tmp = kdtree(A, b)

def knn(i, b, k):
    A = random(i).reshape((i/3,3))
    a = random(3)
    tmp = kdtree(A, b)
    tmpk = tmp.knn(a, 30)


def kdt_bench():
    for i in [30, 300, 3000, 30000, 300000, 3000000]:
        for b in [5, 10, 15]:
            reps = 3000000 / i
            tm = Timer('kdt(%s, %s)' % (i, b), 'from __main__ import kdt')
            print reps, i, b, min(tm.repeat(reps, 3))

def knn_bench():
    for i in [30, 300, 3000, 30000, 300000, 3000000]:
        for k in [3, 30, 300, 3000]:
            reps = 3000000 / i
            tm = Timer('knn(%s, %s, %s)' % (i, 10, k), 'from __main__ import knn')
            print reps, i, k, min(tm.repeat(reps, 3))

knn_bench()
kdt_bench()
